<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Page</title>
    <!-- 引入Bootstrap CSS -->
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.1.1/jquery.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="col-lg-6">
                    <div class="info d-flex align-items-center">
                        <div class="content">
                            <div class="logo">
                                <h3 class="text-input-context-menu">欢迎登录</h3>
                            </div>
                            <p>用户信息管理系统</p>
                        </div>
                    </div>
                </div>
                <div class="card-body">

                    <div class="mb-3">
                        <label for="username" class="form-label">账号</label>
                        <input type="text" class="form-control" id="username">
                        <span style="color:red;" id="accountmust"></span>
                    </div>
                    <div class="mb-3">
                        <label for="password" class="form-label">密码</label>
                        <input type="password" class="form-control" id="password">
                        <span style="color:red;" id="passwordmust"></span>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary btn-block" onclick="login()">登录</button>
                        <button type="submit" class="btn btn-success btn-block" onclick="register()">注册</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 引入Bootstrap Bundle JS (包含 Popper) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
<script>
    function login() {
        $("#accountmust").text("");
        $("#passwordmust").text("");
        var username=$("#username").val();
        var password=$("#password").val();

        if (username.trim()==""||username==null){
            $("#accountmust").text("必填");
            return;
        }
        if (password.trim()==""||password==null){
            $("#passwordmust").text("必填");
            return;
        }
        var acc=username.trim();
        var pass=password.trim();
        $.ajax({
            url:"system/login",
            data:{
                username:acc,
                password:pass
            },
            type:"get",
            success:function(msg){
                console.log(msg);
                if (msg.code==200){
                    alert(msg.message);
                    console.log(msg.data);
                    sessionStorage.setItem('loginUser', JSON.stringify(msg.data));
                    window.location.href="main.html";
                }else if (msg.code==403){
                    alert(msg.message);
                    alert("用户名或者密码错误，请重新输入")
                }
            },
            dataType:"JSON"
        });
    }
    function register() {
        window.location.href="register.html";
    }
</script>
</html>
